<?php

namespace app\index\controller;

use think\Controller;
use think\Request;
use think\Db;
use think\Session;

class Integral extends Controller
{
    /**
     * 查询并计算总积分
     *
     * @return \think\Response
     */
    public function sum()
    {
        if(session('login_admin')['id']){$lid=session('login_admin')['id'];}else{$lid=session('login_tel')['id'];}
        //获取用户的session数据
        $id=$lid;
        $jifen = Db::name('index_integral')->where('lid',$id)->field('jifen')->select();
        $sum = 0;
        foreach($jifen as $v){
            $sum += $v['jifen'];
        }

        //查询积分
        $jf = Db::name('index_integral')->where('lid',$id)->select();
        foreach($jf as $key=>$val){
            $jf[$key]['order'] = Db::name('order_detials')->where('id',$val['oid'])->field('order_no,house_id,input_person_name')->find();
        }
        foreach($jf as $key=>$v){
            $jf[$key]['house'] = Db::name('house_details')->where('id',$v['order']['house_id'])->field('house_name,house_pic,house_address')->find();
        }
//        var_dump($jf);die;
        //从数据库导出导航条数据
        $list = Db::name('index_navigation')->select();
        //从数据库里查询友情链接
        $data = Db::table('lt_link')->select();

        //从数据库里查询用户表数据
        $result = Db::table('lt_index_login')->where('id',$id)->select();
        $this->assign('jf',$jf);
        return view('integral/index',[
            'data'=>$data,
            'info'=>$list,
            'result'=>$result,
            'sum'=>$sum
        ]);
    }
}
